<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title></title>
		<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js" type="text/javascript"></script>
		<script>
			function setCookie(name,value)
			{
				var Days = 30;
				var exp = new Date();
				exp.setTime(exp.getTime() + Days*24*60*60*1000);
				document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
			}
			
			function getCookie(name)
			{
				var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
				if(arr=document.cookie.match(reg))
				return unescape(arr[2]);
				else
				return '';
			}
			
			function decrypt(str, pwd) {
				  if(str == null || str.length < 8) {
				    alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");
				    return;
				  }
				  if(pwd == null || pwd.length <= 0) {
				    alert("Please enter a password with which to decrypt the message.");
				    return;
				  }
				  var prand = "";
				  for(var i=0; i<pwd.length; i++) {
				    prand += pwd.charCodeAt(i).toString();
				  }
				  var sPos = Math.floor(prand.length / 5);
				  var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
				  var incr = Math.round(pwd.length / 2);
				  var modu = Math.pow(2, 31) - 1;
				  var salt = parseInt(str.substring(str.length - 8, str.length), 16);
				  str = str.substring(0, str.length - 8);
				  prand += salt;
				  while(prand.length > 10) {
				    prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
				  }
				  prand = (mult * prand + incr) % modu;
				  var enc_chr = "";
				  var enc_str = "";
				  for(var i=0; i<str.length; i+=2) {
				    enc_chr = parseInt(parseInt(str.substring(i, i+2), 16) ^ Math.floor((prand / modu) * 255));
				    enc_str += String.fromCharCode(enc_chr);
				    prand = (mult * prand + incr) % modu;
				  }
				  return enc_str;
				}
			
				function delCookie(name)
				{
				var exp = new Date();
				exp.setTime(exp.getTime() - 1);
				var cval=getCookie(name);
				if(cval!=null)
				document.cookie= name + "="+cval+";expires="+exp.toGMTString();
				}
			
			
			$(document).ready(function(){
				
				var cookie = getCookie('x-auth-token');
				if(cookie!=null&&cookie!=''){
					   var key =  decrypt(getCookie('x-auth-token'),'kuaige') ;
				}
				
				$('#admin2').click(function(){
					var url=$(this).val();
					$.ajax({
						type:'post',
						url:url,
						data:{},
						async: false,
						dataType:'json',
						contentType:'application/json;charest=utf-8',
		                beforeSend: function(request){
		                    request.setRequestHeader("x-auth-token",key);
		                },
		                success: function(result){
		                	if(result.code=='LOGIN_OUT'){
		                		 delCookie('x-auth-token');
		                		 location.href='http://127.0.0.1:8092/login.html';
		                	}
		                    alert(result.code+"----"+result.msg);
		                }, error: function(XMLHttpRequest, textStatus, errorThrown) {
		                	 alert(textStatus+":"+errorThrown);
		               }
					});
				});
			});
		</script>
	</head>
	<body>
		<div>菜单admin1(有权限)：<input  type="button" id="admin1" class="menu" value="http://127.0.0.1:8092/api/v1/wechat_service/admin/admin1"/> </div>
	    <div>菜单admin2(没设置权限标签)：<input type="button" id="admin2" class="menu" value="http://127.0.0.1:8092/api/v1/wechat_service/admin/admin2"/> </div>
		<div>菜单admin3(无权限)：<input type="button" id="admin3" class="menu" value="http://127.0.0.1:8092/api/v1/wechat_service/admin/admin3"/> </div>
		<div>菜单logout(退出)： <input type="button" id="admin4" class="menu" value="http://127.0.0.1:8092/api/v1/wechat_service/admin/logout"/></div>
	</body>
</html>
